import { showToast } from 'vant'
const colors = {
  买入: 'linear-gradient(135deg, #07c160, #06ae56)',
  卖出: 'linear-gradient(135deg, #ee0a24, #d50a20)',
  持有: 'linear-gradient(135deg, #ff976a, #ff8a5c)',
  观望: 'linear-gradient(135deg, #c8c9cc, #b9babd)',
}
const map: {
  [key: number]: string
} = {
  1: '月线下轨',
  2: '月线中轨',
  3: '轻仓',
}
const postionColors = {
  轻仓: '#00C853', // 高亮绿
  月线中轨: '#FFD600', // 荧光黄
  月线下轨: '#D50000', // 深警示红
}
export const getActionColor = (action: keyof typeof colors) => {
  return colors[action] || '#969799'
}

export const formatStrateOperate = (strateOperate: number) => {
  return map[strateOperate] as keyof typeof postionColors
}
export const getPositionColor = (strateOperate: number) => {
  const format = formatStrateOperate(strateOperate)

  return postionColors[format] || '#f7f8fa'
}

export const copyText = async (content: string) => {
  try {
    await navigator.clipboard.writeText(content)
    showToast('复制成功')
  } catch (err) {
    console.log(err)
    handleFallbackCopy(content)
  }
}
export const handleFallbackCopy = (text: string) => {
  // 兼容旧浏览器方案
  const textArea = document.createElement('textarea')
  textArea.value = text
  document.body.appendChild(textArea)
  textArea.select()
  document.execCommand('copy')
  document.body.removeChild(textArea)
  showToast('复制成功')
}
export const handleDate = (date: string) => {
  const index = date.indexOf('T')
  if (index !== -1) {
    return date.slice(0, index)
  }
  return date
}
